package meijuli.com.join51.business.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import meijuli.com.join51.business.R;
import meijuli.com.join51.business.adapter.FragmentAdapter;
import meijuli.com.join51.business.fragment.OrderListFragment;
import meijuli.com.join51.business.model.Order;

/**
 * 订单管理
 *
 * @author jack 2017-05-02 10:33
 */
public class OrderManagerActivity extends BaseActivity {
    TabLayout mTabLayout;
    Toolbar mToolbar;
    TextView  mTitleText;
    ViewPager mOrderViewPager;
    private List<Fragment> mFragmentList;
    private List<Integer>  mStatusList;
    private List<String>   mTitleList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_manager);
        initData();
        setView();
    }

    private void initData() {
        mFragmentList = new ArrayList<>();
        mStatusList = new ArrayList<>();
        mTitleList = new ArrayList<>();
        mTitleList.add("全部");
        mTitleList.add("未收款");
        mTitleList.add("已收款");
        mStatusList.add(Order.STATUS_ALL);
        mStatusList.add(Order.STATUS_WAIT_PAYMENT);
        mStatusList.add(Order.STATUS_SUCCESS);

        for(int i = 0; i < mStatusList.size(); i ++) {
            mFragmentList.add(OrderListFragment.newInstance(mStatusList.get(i)));
        }
    }

    private void setView() {
        mTabLayout = findViewById(R.id.tablayout);
        mToolbar = findViewById(R.id.toolbar);
        mTitleText = findViewById(R.id.toolbar_title);
        mOrderViewPager = findViewById(R.id.viewpager_order);
        mTitleText.setText("订单管理");
        mToolbar.setNavigationIcon(R.mipmap.icon_back_white);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        mOrderViewPager.setOffscreenPageLimit(3);
        mOrderViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager(),
                                   mFragmentList,
                                   mTitleList));
        mTabLayout.setupWithViewPager(mOrderViewPager);
    }

}
